package com.android.support.lib.universal.util;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;

import android.util.Log;

public class Utilstr {
	/**
	 * 去除字符串双引号
	 * 
	 * @return
	 */
	public  String removeMarks(String result) {
		result = result.replace("\"", "");
		return result;
	}

	/**
	 * 流转化为 String
	 * 
	 * @param inputstream
	 *            流
	 * @param character
	 *            字符编码，可以是"UTF-8"(空值默认),"GB2312"( 文件的编码格式),"ISO8859-1"
	 * @return
	 */
	public  String readInput(InputStream inputstream, String character) {
		String detials = null;
		try {
			if (character == null || character.equals("")) {
				character = "UTF-8";
			}
			BufferedReader br = new BufferedReader(new InputStreamReader(
					inputstream, character));
			String line = "";
			StringBuffer temp = null;
			temp = new StringBuffer("");
			while ((line = br.readLine()) != null) {
				temp.append(line);
			}
			detials = new String(temp);// String文本内容
			br.close();
		} catch (Exception e) {
			// TODO: handle exception
		}
		return detials;
	}

	/**
	 * Stirng 转化为流
	 * 
	 * @param detials
	 *            字符串
	 * @param character
	 *            字符编码，可以是"UTF-8"(空值默认),"GB2312"( 文件的编码格式),"ISO8859-1"
	 * @return
	 */
	public  InputStream getInputStream(String detials, String character) {
		InputStream inputstream = null;
		try {
			if (character == null || character.equals("")) {
				character = "UTF-8";
			}
			inputstream = new ByteArrayInputStream(detials.getBytes(character));
		} catch (Exception e) {
			// TODO: handle exception
			Log.e("test", "流转化异常"+e.getMessage());
		}
		return inputstream;
	}
}
